﻿using Swifter.RW;
#if UNITY
using UnityEngine;
#else
using System.Numerics;
#endif

namespace SwifterJson
{
    public class Vector3Interface : IValueInterface<Vector3>
    {
        public Vector3 ReadValue(IValueReader valueReader)
        {
            var str = valueReader.ReadString();
            return Parse2Vec3(str);
        }

        public void WriteValue(IValueWriter valueWriter, Vector3 value)
        {
            var str = string.Format("{0},{1},{2}", value.X, value.Y, value.Z);
            valueWriter.WriteString(str);
        }

        public static Vector3 Parse2Vec3(string str)
        {
            var s = str.Split(',');
            return new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2]));
        }
    }

    public class Vector3InterfaceMaper : IValueInterfaceMaper
    {
        public IValueInterface<Vector3> TryMap<Vector3>()
        {
            return new Vector3Interface() as IValueInterface<Vector3>;
        }
    }
}
